//
/**
 * @func
 * @desc 去除url中指定查询字段
 * @param {String} url 要处理的url
 * @param {String} query 要去除的查询字段
 * @param {String} mode
 * @returns String
 * */
export function deleteUrlQuery(url, query, mode = 'history') {
  if (mode === 'history') {
    const urlObj = new URL(url)
    urlObj.searchParams.delete(query)
    return urlObj.toString()
  }
  if (mode === 'hash') {
    const urlPath = url.split('?')[0]
    const queryObj = url.split('?')[1]
    if (queryObj) {
      const arr = queryObj.split('&').filter((n) => !n.startsWith(`${query}=`))
      if (arr.length > 0) {
        return `${urlPath}?${arr.join('&')}`
      }
      return urlPath
    }
    return url
  }

  return url
}
